<?php

class Admini_PaypalController extends Uuch_ManageController {

    public function init() {
        parent::init();
        $this->appendCss('/css/Share.css');
        $this->appendCss('/css/home/warehouse.css');
        $this->appendCss('/admins/css/common.css');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');
        $this->view->type = "risk";
    }

    public function indexAction() {
		
	}
    
    public function riskAction()
    {
        $this->setTitle("Paypal风控记录");
        $pagesize = 10;
        $pageindex = $this->getSafeParam('start');
        if (!$pageindex) {
            $pageindex = 0;
        }
        $quick = $this->getSafeParam("quick");
        $dateinbegin = $this->getSafeParam("dateinbegin");
        $dateinend = $this->getSafeParam("dateinend");
        
        $status = $this->getSafeParam('status');
        if($status=='history'){
        	$data = Application_Model_PaypalRisk::getFilters($quick, $dateinbegin,$dateinend, $pagesize, $pageindex);	
        	$this->view->stype = 7; 
        }else{
	        $data = Application_Model_PaypalRisk::getFilter($quick, $dateinbegin,$dateinend, $pagesize, $pageindex);	
	        $this->view->stype = 16;     
	   }   
	   	$this->view->data = $data;
        $this->view->items = $data["list"];
										       
        $this->view->quick = $quick;
        $this->view->dateinbegin = $dateinbegin;
        $this->view->dateinend = $dateinend;
    }
	
	public function paypallistAction(){
		$status = $this->getSafeParam("status");
		if($status=='verified'){
			$this->view->stype = 1;
		}
		else if($status=='unverified'){
			$this->view->stype = 2;
		}
		else if($status==Application_Model_PaypalAccount::Uuch_Status_Verified){
			$this->view->stype = 3;
		}
		else if($status==Application_Model_PaypalAccount::Uuch_Status_Default){
			$this->view->stype = 4;
		}
		else if($status==Application_Model_PaypalAccount::Uuch_Status_Black){
			$this->view->stype = 5;
		}
		else if($status==6){
			$this->view->stype = 6;
		}
		
		$pagesize = 10;
		$pageindex = $this->getSafeParam('start');
        if (!$pageindex) {
            $pageindex = 0;
        }
		$quick = $this->getSafeParam("quick");
        $dateinbegin = $this->getSafeParam("dateinbegin");
        $dateinend = $this->getSafeParam("dateinend");
		$data=Application_Model_PaypalAccount::getFilter($status,$quick, $dateinbegin,$dateinend, $pagesize, $pageindex);
		$this->view->data=$data;
		$this->view->Isapprove = $data["list"];
		$this->view->quick = $quick;
        $this->view->dateinbegin = $dateinbegin;
        $this->view->dateinend = $dateinend;
	}

	public function setuuchstateAction() 
	{
		$id = $this->getRequest()->getParam('id', '');
		$status = $this->getRequest()->getParam('status', '');
		$result = 0;
		if ($status != '' && $id != '') {
			$model = Application_Model_PaypalAccount::load($id);
			if ($model) {
				switch($status) {
					case 'pass':
						$model->Uuch_user_status = Application_Model_PaypalAccount::Uuch_Status_Verified;
						$model->save();
						break;
					case 'unpass':
						$model->Uuch_user_status = Application_Model_PaypalAccount::Uuch_Status_Default;	
						$model->save();					
						break;
					case 'black':	
						$model->Uuch_user_status = Application_Model_PaypalAccount::Uuch_Status_Black;
						$model->save();
						break;
				}				
				$result = 1;
			}
		}
		echo $result;exit;
	}

	public function setstatusAction() 
	{
		$id = $this->getRequest()->getParam('id', '');
		$status = $this->getRequest()->getParam('status', '');
		$result = 0;
		if ($status != '' && $id != '') {
			$model = Application_Model_PaypalRisk::load($id);
			if ($model) {
				$account = Application_Model_PaypalAccount::loadByIdAndEmail($model->Uuch_user_id, $model->Payer_email);
				switch($status) {
					case 'black':
						$account->Uuch_user_status = Application_Model_PaypalAccount::Uuch_Status_Black;
						$account->save();
						$model->Remark .=Uuch_Util::getUserNikeName().'将记录已拉入黑名单'.';';
						$model->pass=50;
						$model->save();
						break;
					case 'white':
						$account->Uuch_user_status = Application_Model_PaypalAccount::Uuch_Status_Verified;	
						$account->save();					
						$model->Remark .= Uuch_Util::getUserNikeName().'将记录已设为悠奇认证'.';';
						$model->Pass = 100;
						$model->save();
						break;
					case 'pass':	
						$model->Pass = 1;				
						$model->Remark .= Uuch_Util::getUserNikeName(). '将记录已设为本次通过'.';';
						$model->save();
						break;
				}				
				$result = 1;
			}
		}
		echo $result;exit;
	}

	public function upremarkAction() 
	{
		$id = $this->getRequest()->getParam('id','');
		$remark = $this->getRequest()->getParam('remark', '');
		$result = 0;
		$model = Application_Model_User::load($id);
		if ($remark != $model->paypal && $id != '') {
			$model->paypal = $remark;
			$model->save();
			$result = 1;
		}		
		echo $result;exit;		
	}

	public function getpaypallistAction()	
	{
		$userId = $this->getRequest()->getParam('userid', 0);
		$data = Application_Model_PaypalAccount::loadByUserId($userId);
		$email = array('关联的paypal帐号:');
		foreach($data as $item) {
			$email[] = $item->Payer_email;
		}
		echo implode("\r\n", $email);
		exit;
	}
	
	public function getuserlistAction() {		
		$paypal = $this->getRequest()->getParam('paypal', 0);
		$data = Application_Model_PaypalAccount::loadByPaypal($paypal);
		$user = array('关联的悠奇帐号:');
		foreach($data as $item) {
			$user[] = $item->Uuch_user_id;
		}
		echo implode("\r\n", $user);
		exit;
	}

}